
import 'package:flutterdouban/model/homeModel/home_movelist_model.dart';
import 'package:flutterdouban/service/http_request.dart';

class HomeRequest {

  /* 首页列表的网络请求 */
  static Future<List<MovieItem>> requestMoveList(int start) async {
    // 1.构建url
    final movieUrl = 'https://douban.uieee.com/v2/movie/top250';
    // 请求的数量， 20条
    int movieCount = 20;

    // 2.发送网络请求，等待结果
    final result = await HttpRequest.get(movieUrl, params: {'start': start, 'count': movieCount});
    final subjects = result['subjects'];

    // 3.将Map转成Model
    List<MovieItem> movies = [];
    for (var sub in subjects) {
      movies.add(MovieItem.fromMap(sub));
    }

    return movies;
  }
}